package com.kitty.game.guard;

import com.kitty.game.config.GuardSet;
import com.kitty.common.utils.SpringUtils;
import com.kitty.game.config.Reloadable;
import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Component
public class GuardDataPool implements Reloadable {

    /**守护名对应守护配置*/
    public static Map<String , GuardSet> guardSetMap;

    @Override
    public void reload() {
        Dao dao = SpringUtils.getBean(Dao.class);
        List<GuardSet> list = dao.query(GuardSet.class, Cnd.NEW());
        Map<String, GuardSet> guardSetMap = new HashMap<>(list.size());

        for (GuardSet guardSet : list) {
            guardSetMap.put(guardSet.getName(), guardSet);
        }

        GuardDataPool.guardSetMap = guardSetMap;
    }
}
